package com.data.JVM;

import sun.misc.Unsafe;

import java.lang.reflect.Field;

/**
 * Created by wangbing on 2018/6/1.
 */
public class DirectMemoryOOM {
    private static final int _1M = 1024*1024;

    public static void main(String[] args) throws IllegalAccessException {
        Field unsafeField = Unsafe.class.getDeclaredFields()[0];

        unsafeField.setAccessible(true);

        Unsafe unsafe = (Unsafe) unsafeField.get(null);
        int i = 0;
        while (true){
            System.out.println("第"+(i++)+"次分配内存");
            unsafe.allocateMemory(_1M);
        }
    }
}
